import random
from django.http import JsonResponse
from rest_framework.views import  APIView
from lxml import etree
from dal import models



class BarData(APIView):

    def get(self, request):
        data = {}

        x_list = []
        y_list = []

        try:
            res_obj = models.DoubanTop.objects.order_by("id")
            for obj in res_obj:
                x_list.append(obj.title[0:5])
                y_list.append(obj.rate)

            data['x_list'] = x_list
            data['y_list'] = y_list

            return JsonResponse(data)

        except Exception as e:
            print(e)
            data['code'] = 444
            return JsonResponse(data)



